<?php
// 本类由系统自动生成，仅供测试用途
class ArtcAction extends BaseAction{

	public function show() {
	
    	$dao = D('Artc');
		$dao_sort = D('Sort');
		
    	$id = (int)$_GET['id'];		
     	$vo = $dao->find($id);	//文章		
     	
     	if( $vo['checked'] ==0 )
     	{
     		$this->error('文章未通过审核！');
     	}
     	
		$sort = $dao_sort->find($vo['pid']); //分类
		if( !empty($sort['img']) )
		{
			$img_dir = C('ARTC_IMG_DIR');
			$sort['img_url'] = $img_dir.$sort['img'];
			$sort['simg_url'] = $img_dir.'s_'.$sort['img'];
		}
		
		//TODO 得到自定义表单
		if( !empty($sort['form_id']) )
		{
			$fid=(int)$sort['form_id'];
			$m_form = D("Form");
			$fm = $m_form->where("id={$fid}")->find();
			
			$field_list = unserialize($fm['content']);
			
			for($i=0;$i<count($field_list);$i++) {
				$field_list[$i]['fval_list'] = explode('|', $field_list[$i]['fvalue']);
			}
			
			$this->assign("form_id",$fm['id']);
			$this->assign('form_title',$fm['title']);
			$this->assign('field_list',$field_list);
			
			
		} 
		
		//标题
		$title = empty($vo['web_title'])? $vo['title']:$vo['web_title'];
		$web_title = $title.' - '.$this->webInfo['web_title'];
		//关键词
		$keyword = empty( $vo['web_key'] )? $this->webInfo['web_key']:$vo['web_key'];
		$web_keyword = $title.','.$keyword;
		//描述
		$descp = empty( $vo['web_desc'] ) ? $this->webInfo['web_desc']: $vo['web_desc'];
		$web_desc = $title.','.$descp;
		
		//输出变量到模板
		$this->assign('web_title',$web_title);
		$this->assign('web_key',$web_keyword);
		$this->assign('web_desc',$web_desc);
		$this->assign('vo',$vo);		//文章
		$this->assign('sort',$sort);	//分类
     	
		
		//模板
		if( empty($vo['content_tpl_id']) )	//继承上级模板（使用栏目的content模板）
		{
			$tpl = C('TPL_PATH').$sort['content_tpl_id'].'.html';
		}
		else	//使用定义的模板
		{
			$tpl = C('TPL_PATH').$vo['content_tpl_id'].'.html';
		}
		
		//输出模板		
		$this->display($tpl);

	}

    public function sort() {
		
		$id = (int)$_GET['id'];
		$dao_sort = D('Sort');
		
		$vo = $dao_sort->find($id);
		
		if( !empty($vo['img']) )
		{
			$img_dir = C('ARTC_IMG_DIR');
			$vo['img_url'] = $img_dir.$vo['img'];
			$vo['simg_url'] = $img_dir.'s_'.$vo['img'];
		}
		
		
		//标题
		$title = $vo['name'];
		$web_title = $title.' - '.$this->webInfo['web_title'];
		//关键词		
		$web_keyword = $title.','.$this->webInfo['web_key'];
		//描述
		$web_desc = $title.','.$this->webInfo['web_desc'];
		
		//输出变量到模板
		$this->assign('web_title',$web_title);
		$this->assign('web_key',$web_keyword);
		$this->assign('web_desc',$web_desc);
		$this->assign('vo',$vo);		//分类信息
		
		
		//模板
		if( $vo['extend_tpl'] == 1)	//继承上级模板（使用栏目的content模板）
		{
			if( $vo['pid'] != 0 )
			{
				$psort = $dao_sort->where('pid='.$id)->select();
				$tpl = C('TPL_PATH').$psort['content_tpl_id'].'.html';
			}
			else
				$tpl = C('TPL_PATH').$vo['list_tpl_id'].'.html';	
		}
		else	//使用定义的模板
		{
			$tpl = C('TPL_PATH').$vo['list_tpl_id'].'.html';
		}
		
		//输出模板		
		$this->display($tpl);
    }

}
?>